//
//  KyHomeViewController.swift
//  KyBase
//
//  Created by fangyukui on 2017/10/16.
//  Copyright © 2017年 fangyukui. All rights reserved.
//

import UIKit
fileprivate let cellID = "cellID"
class KyHomeViewController: KyBaseViewController {
    lazy var statusVM =  KyStatusListViewModel()
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
    }
}

//MARK:设置UI
extension KyHomeViewController{
    override func setupTableView() {
        super.setupTableView()
        kyNaVItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellID)
    }
    
    
    override func loadData() {
        statusVM.getStatus(isPullup: isPullup) { (isSucess) in
            KyLog(message: "加载数据结束")
            self.refreshCtl.endRefreshing()
            self.tableView?.reloadData()
            
            self.isPullup = false
            
        }
     
    }
    
}

//设置事件
extension KyHomeViewController{
    @objc fileprivate func showFriends(){
        let demoVC  = KyDemoViewController()
        navigationController?.pushViewController(demoVC, animated: true)
    }
    
}
//MARK:tableView协议
extension KyHomeViewController{
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusVM.statusList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellID)
        cell.detailTextLabel?.text = statusVM.statusList[indexPath.row].text
        return cell
    }
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 44
        
    }
    
}
